function testNum(x) {
    var res = /^[0-9]+(\.[0-9]+)?$/;
    return res.test(x);
}
var VueObject = function () {
    return {
        kz: '克制',
        atk: 0,
        atk_add: 0,
        atk_del: 0,
        dmg_add1: 0,
        dmg_add2: 0,
        dmg_add3: 0,
        dmg_add4: 0,
        dmg_add5: 0,
        dmg_add6: 0,
        dmg_add7: 0,
        dmg_add8: 50,
        dmg_add9: 0,
        dmg_add10: 0,
        dmg_v: 0,
        dmg_v_cri: 0,
        dmg_def: 0,
        dmg_hit: 50,
        dmg_v_eva: 0,


        hit: 0,
        eva: 0,
        def_minus: 0,
        def: 0,
        enemy_eva: 0,
        enemy_hit: 0,
        rs: '',
        hit_pct: 0,
        eva_pct: 0,
        def_pct: 0,
        enemy_eva_pct: 0,
        enemy_hit_pct: 0,
        boss_2: '',
        boss_data: 
        {
            湖中骑士: {
                hp: 1549766,
                def: 1864,
                hit: 5292,
                eva: 1324,
            },
            克隆骑士:
            { 
                hp: 0,
                def: 0,
                hit: 0,
                eva: 0,
            },
            暴君盾:
            {
                hp: 1416578,
                def: 3389,
                hit: 1973,
                eva: 1158 
            }
        } 
        ,
        boss: [
            {
                index: '0',
                name: '湖中骑士'
                
            },
            /*
            {
                index: '1',
                name: '克隆骑士' 
            },*/
            {
                index: '2',
                name: '暴君盾' 
                 
            }
        ],

    };

};


var VueFunc_PC = {
    boss2_change(xxxx) {
        var x = this.boss_data[this.boss_2];
        this.enemy_hit = x.hit;
        this.enemy_eva = x.eva;
        this.def = x.def; 
        this.hitcalc();
    },
    hitcalc() {
        this.hit_pct = (this.hit * 100 / (this.hit + 1500)).toFixed(4);
        this.eva_pct = (this.eva * 100 / (this.eva + 800)).toFixed(4); 
        this.def_pct = (this.def * 100 / (this.def + 999)).toFixed(4);
        this.enemy_eva_pct = (this.enemy_eva * 100 / (this.enemy_eva + 800)).toFixed(4);
        this.enemy_hit_pct = (this.enemy_hit * 100 / (this.enemy_hit + 1500)).toFixed(4);
        var Ndef=this.def * (100 - this.def_minus) / 100;
        var Ndef_pct = (Ndef * 100 / (Ndef + 999)).toFixed(4);
        this.rs = '敌方防御数值为' + Ndef + ',防御减伤比率=' + Ndef_pct + '%\r\n';  
        /**
         * 命中Y=X/(X+1500)
         * 闪避Z=E/(E+800)
         * Y>=Z
         * 即X/(X+1500)>=Z
         * X>=Z*(X+1500)
         * X>=ZX+1500Z
         * X-ZX>=1500Z
         * (1-Z)X>=1500Z
         * X>=1500Z/(1-Z)
         */
        this.rs += '我方需要命中数值' + (1500 * this.enemy_eva_pct / 100 / (1 - this.enemy_eva_pct / 100)).toFixed(4) + '以达到必中\r\n';
        var eva_50 = this.enemy_eva * 0.5;
        var eva_50pct = (eva_50 * 100 / (eva_50 + 800)).toFixed(4);
        console.log('eav50=' + eva_50 + ',pct=' + eva_50pct+'%');
        this.rs += '我方在企业/足球妹减50%闪避下,需要命中数值' + (1500 * eva_50pct / 100 / (1 - eva_50pct / 100)).toFixed(4) + '以达到必中\r\n'; 

        this.rs += '我方前排需要闪避数值' + (800 * this.enemy_hit_pct / 100 / (1 - this.enemy_hit_pct / 100)).toFixed(4) + '以防止BOSS必中\r\n';
    },

    enemy_hit_change(x) {
        if (!testNum(x)) {
            this.enemy_hit = 0;
        } else {
            this.enemy_hit = parseInt(x);
        }
        this.hitcalc();
    }, 
    enemy_eva_change(x) {
        if (!testNum(x)) {
            this.enemy_eva = 0;
        } else {
            this.enemy_eva = parseInt(x);
        }
        this.hitcalc();
    },
    def_change(x) {
        if (!testNum(x)) {
            this.def = 0;
        } else {
            this.def = parseInt(x);
        }
        this.hitcalc();
    },
    def_minus_change(x) { 
            if (!testNum(x)) {
                this.def_minus = 0;
            } else {
                this.def_minus = parseInt(x);
        }
        this.hitcalc();
    },
    hit_change(x) {
        if (!testNum(x)) {
            this.hit = 0;
        } else {
            this.hit = parseInt(x);
        }
        this.hitcalc();
    }, 
    eva_change(x) {
        if (!testNum(x)) {
            this.eva = 0;
        } else {
            this.eva = parseInt(x);
        }
        this.hitcalc();
    },  
    dmg_hit_change(x) {
        if (!testNum(x)) {
            this.dmg_hit = 0;
        } else {
            this.dmg_hit = parseInt(x);
        }
        this.calcData();
    },
    dmg_def_change(x) {
        if (!testNum(x)) {
            this.dmg_def = 0;
        } else {
            this.dmg_def = parseInt(x);
        }
        this.calcData();
    },
    dmg_add1_change(x) { 
        if (!testNum(x)) {
            this.dmg_add1 = 0;
        } else {
            this.dmg_add1 = parseInt(x);
        }
        this.calcData();
    },
    dmg_add2_change(x) { 
        if (!testNum(x)) {
            this.dmg_add2 = 0;
        } else {
            this.dmg_add2 = parseInt(x);
        }
        this.calcData();
    },
    dmg_add3_change(x) { 
        if (!testNum(x)) {
            this.dmg_add3 = 0;
        } else {
            this.dmg_add3 = parseInt(x);
        }
        this.calcData();
    },
    dmg_add4_change(x) {
        var isN = testNum(x);
        if (!testNum(x)) {
            this.dmg_add4 = 0;
        } else {
            this.dmg_add4 = parseInt(x);
        }
        this.calcData();
    },
    dmg_add5_change(x) { 
        if (!testNum(x)) {
            this.dmg_add5 = 0;
        } else {
            this.dmg_add5 = parseInt(x);
        }
        this.calcData();
    },
    dmg_add6_change(x) { 
        if (!testNum(x)) {
            this.dmg_add6 = 0;
        } else {
            this.dmg_add6 = parseInt(x);
        }
        this.calcData();
    },

    dmg_add6_change(x) { 
        if (!testNum(x)) {
            this.dmg_add6 = 0;
        } else {
            this.dmg_add6 = parseInt(x);
        }
        this.calcData();
    },

    dmg_add7_change(x) { 
        if (!testNum(x)) {
            this.dmg_add7 = 0;
        } else {
            this.dmg_add7 = parseInt(x);
        }
        this.calcData();
    },
    dmg_add8_change(x) { 
        if (!testNum(x)) {
            this.dmg_add8 = 0;
        } else {
            this.dmg_add8 = parseInt(x);
        }
        this.calcData();
    },
    dmg_add9_change(x) { 
        if (!testNum(x)) {
            this.dmg_add9 = 0;
        } else {
            this.dmg_add9 = parseInt(x);
        }
        this.calcData();
    },
    dmg_add10_change(x) { 
        if (!testNum(x)) {
            this.dmg_add10 = 0;
        } else {
            this.dmg_add10 = parseInt(x);
        }
        this.calcData();
    },
    dmg_add11_change(x) { 
        if (!testNum(x)) {
            this.dmg_add11 = 0;
        } else {
            this.dmg_add11 = parseInt(x);
        }
        this.calcData();
    },
    dmg_add12_change(x) { 
        if (!testNum(x)) {
            this.dmg_add12 = 0;
        } else {
            this.dmg_add12 = parseInt(x);
        }
        this.calcData();
    },
 
    atk_add_change(x) { 
        if (!testNum(x)) {
            this.atk_add = 0;
        } else {
            this.atk_add = parseInt(x);
        }
        this.calcData();
    }, atk_del_change(x) { 
        if (!testNum(x)) {
            this.atk_del = 0;
        } else {
            this.atk_del = parseInt(x);
        }
        this.calcData();
    },
    atk_change(x) {
        if (!testNum(x)) {
            this.atk = 0;
        } else {
            this.atk = parseInt(x);
        }
        this.calcData();
    },
    kz_change(x) {

        this.calcData();
    },
    checkData() {

    },
    calcData() { 
        var dmg1= (this.atk) * (100 + (this.atk_add) - (this.atk_del)) / 100 * (100 + this.dmg_add1 + this.dmg_add2 + this.dmg_add3 + this.dmg_add4) / 100; 
        if (this.kz === '克制') {
            dmg1 = dmg1 + dmg1 * 0.3 * (this.dmg_add5 + 100) / 100;
        } else if (this.kz === '被克制') {
            dmg1 = dmg1 * 0.7;
        } else if (this.kz === '不克制') {

        }
        dmg1 = dmg1 * (this.dmg_add6 + 100) / 100 * (this.dmg_add7 + 100) / 100 * (100 - this.dmg_def)/100;
        this.dmg_v = dmg1;
        this.dmg_v_cri = dmg1 * (this.dmg_add8 + 100) / 100;
        this.dmg_v_eva = this.dmg_v * (this.dmg_hit+10)/100;
        
    },
    CloseAllPages() {

    },
    handleSelect(key, keyPath) {
    },
}; 

new Vue({
    el: '#app',
    data: VueObject,
    methods: VueFunc_PC
})